<template>
	<view class="notice-view">
		<view class="notice-list" v-if="noticeList.length">
			<view class="notice-item" @click="go(item)" v-for="(item, index) in noticeList" :key="index">
				<view class="notice-title">
					<view class="notice-left">
						{{$t('language')=="zh"?item.remark:item.remark1}}
					</view>

					<view class="notice-right" v-if="item.remark2 != 0">
						{{$t("appNotice.details")}}
						<view class="red" v-if="item.informStatus==1">

						</view>
					</view>
				</view>

				<view class="notice-content">
					{{$t('language')=="zh"?item.informText:item.informTextEn}}
				</view>

				<view class="date">
					{{item.creatTime}}
				</view>
			</view>
		</view>
		<view class="notice-list" v-else>
			<uni-section title="" subTitle="" type="line">
						<uni-notice-bar show-icon text="No new notifications" />
			</uni-section>
		</view>
	</view>
</template>

<script>
	import { getInform, putInform } from "@/common/api.js"

	export default {
		data() {
			return {
				noticeList: []
			}
		},
		methods: {
			async initData() {
				const res = await getInform({
					userId: uni.getStorageSync("userId"),
					pageSize: 1000
				});

				console.log(res);
				this.noticeList = res.rows;
			},
			async go(item) {
				const res = await putInform({
					id: item.id,
					informStatus: 0
				});

				console.log(res);

				if(item.remark2 == 4) {
					uni.navigateTo({
						url:`/pages/commodityDetails/commodityDetails?id=${item.goodsId}`
					})
					return
				}

				if(item.remark2 == 3) {
					uni.navigateTo({
						url: `/pages/goodsPublish/goodsPublish`,
					})
					return
				}

				if(item.remark2 == 1) {
					uni.navigateTo({
						url: `/pages/lookPrice/lookPrice?id=${item.goodsId}`,
					})
					return
				}

				if(item.remark2 == 2) {
					uni.navigateTo({
						url: `/pages/orderDetils/orderDetils?id=${item.orderId}`
					})
					return
				}
			}
		},
		onShow() {
			this.initData();
		},
		onReady() {
			uni.setNavigationBarTitle({ title: this.$t("noticeCenter.title")});
		}
	}
</script>

<style lang="scss" scoped>
	.notice-view {
		padding: 20rpx;
		padding-top: 0;
	}

	.notice-list {
		.notice-item {
			margin-top: 30rpx;
			box-shadow: 0px 0px 8px 0px #00000019;
			border-radius: 20rpx;

			.notice-title {
				padding: 20rpx 0;
				margin: 0 20rpx;
				border-bottom: 3rpx solid #afafaf;
				display: flex;
				align-items: center;
				justify-content: space-between;

				.notice-left {
					font-size: 34rpx;
					font-weight: bold;
				}

				.notice-right {
					margin-top: 15rpx;
					font-size: 28rpx;
					color: #afafaf;
					font-weight: bold;
					position: relative;

					.red {
						position: absolute;
						right: 0;
						top: -18rpx;
						width: 10rpx;
						height: 10rpx;
						background-color: red;
						border-radius: 50%;
					}
				}
			}

			.notice-content {
				width: 97%;
				padding: 20rpx;
				font-size: 26rpx;
				color: #858585;
			}

			.date {
				font-size: 22rpx;
				font-weight: bold;
				padding: 20rpx;
				padding-top: 0;
				text-align: right;
				color: #afafaf;
			}
		}
	}
</style>
